package com.d3works.apps.account.service;

import com.d3works.apps.account.db.repo.AccountingSituationRepository;
import com.d3works.apps.base.service.user.UserServiceImpl;
import com.d3works.auth.db.User;
import com.d3works.exception.D3worksException;
import com.d3works.inject.Beans;
import com.google.inject.persist.Transactional;

public class UserServiceAccountImpl extends UserServiceImpl {

  @Transactional(rollbackOn = {D3worksException.class, Exception.class})
  public int changePfpValidator(User pfpValidatorUser, User newPfpValidatorUser) {

    return Beans.get(AccountingSituationRepository.class)
        .all()
        .filter(
            "self.pfpValidatorUser = ? and self.company in ? and self.company in ?",
            pfpValidatorUser,
            pfpValidatorUser.getCompanySet(),
            newPfpValidatorUser.getCompanySet())
        .update("pfpValidatorUser", newPfpValidatorUser);
  }
}
